//
//  ShopAffairViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-1-8.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "StockViewController.h"

@interface StockViewController ()
{
    NSUInteger previousSelectedIndex;
}
@end

@implementation StockViewController
@synthesize cellSelectedIndex=_cellSelectedIndex;
@synthesize shopAffairViewControllers = _shopAffairViewControllers;
-(void)viewWillAppear:(BOOL)animated
{
  //  NSLog(@"ttttttttt");
    [Global setHomeCustomID:2];
    _cellSelectedIndex=[Global getStockID];
    [self setSelectedIndex:_cellSelectedIndex];
    
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (selectedIndex<[self.shopAffairViewControllers count]) {
        if (previousSelectedIndex != NSNotFound)
        {
            UIViewController *previousViewController = [self.shopAffairViewControllers objectAtIndex:previousSelectedIndex];
            [previousViewController.view removeFromSuperview];
            [previousViewController removeFromParentViewController];
        }
        
        UIViewController *selectedViewController = [self.shopAffairViewControllers objectAtIndex:selectedIndex];
        [self addChildViewController:selectedViewController];
        selectedViewController.view.frame = CGRectMake(0, 0,948,768);
        selectedViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [self.view addSubview:selectedViewController.view];
        // remove previously selected view controller (if any)
        previousSelectedIndex=selectedIndex;
    }
    
}
- (void)setShopAffairViewControllers:(NSArray *)viewControllers
{
    _shopAffairViewControllers = [viewControllers copy];
    previousSelectedIndex=NSNotFound;
    // create tab bar items
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
